var iplus;
var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
(function ($) {
    iplus = {
        window: $(window),
        document: $(document),
        setup: function () {
            /*this.fullscreen();*/
            this.videoscreen();
            this.showHeader();
            this.goTop();
            this.shareMedia();
            this.offCanvas();
            /*     this.instagram();*/
            this.openWechat();
            this.indexSlide();
            this.sitesearch();
            this.aboutTab();
            this.brandInfo();
            this.swiperBanner();
        },
        init: function () {
            this.setup();
            $('.mouse-scroll').on('click', function () {
                $body.animate({
                    scrollTop: $('.page').offset().top - 70
                }, 700, 'easeInOutCirc', function () {
                    // console.log('top');
                });
                return false;
            });
            if ($('.full-banner').length > 0) {
                $('.header').removeClass('change');
                $('body').removeClass('is-loading');
            } else {
                $('body').removeClass('is-loading');
            }
            ;
            this.fullscreen();
            $(window).bind('resize', this.fullscreen);
            $(window).bind('resize', this.videoscreen);
            $(window).on('resize load', this.adjustIframes);
        },
        offCanvas: function () {
            $('.main-navi').find('.toggle').on('click', 'a', function (e) {
                var body = $('body');
                var nav = $('.main-navi');
                // if(nav.hasClass('is-open')){
                //   nav.removeClass('is-open');
                // } else{
                //   nav.addClass('is-open');
                // }
                if (body.hasClass('nav-open')) {
                    body.removeClass('nav-open');
                    //收回分享
                    if (nav.find(".msb_main").hasClass("active")) {
                        nav.find(".msb_main").trigger('click');
                    }
                } else {
                    body.addClass('nav-open');
                }
                e.preventDefault();
            });
        },
        showHeader: function () {
            var windowHeight = $(window).outerHeight();
            var bannerHeight = $('.svg-warp').outerHeight();
            var headerHeight = $('.header').outerHeight();
            var activeHeight = 0;
            if ($('.full-banner').length > 0) {
                activeHeight = windowHeight - headerHeight - 50;
            } else {
                activeHeight = bannerHeight - headerHeight - 50;
            }
            $(window).scroll(function () {
                /* if ($('.full-banner').length > 0) {*/
                if ($(window).scrollTop() > activeHeight) {
                    $('.header').addClass('change');
                    $('#store-map').css({
                        'z-index': 2
                    })
                } else {
                    $('.header').removeClass('change');
                    $('#store-map').css({
                        'z-index': 1
                    })
                }
                /*  }*/
            });
        },
        fullscreen: function () {

            var width = $(window).width();
            var height = $(window).height();
            if (width < height) {
                height = "auto";
            }

            $('.full-banner').css({
                width: width,
                height: height
            });
            $('.home-svg').css({
                height: height
            });
        },
        videoscreen: function () {
            var width = $(".video-content").width();
            var height = ($(".video-content").width() * 498 / 640) + 'px';
            $('#video_iframe').css({
                height: height
            });
        },
        goTop: function () {
            var $scPosition = $(window).height();
            $('.goTop').on("click", "a", function () {
                $body.animate({
                    scrollTop: 0
                }, 700, 'easeInOutCirc', function () {
                    // console.log('top');
                });
                return false;
            })

            $(window).bind('scroll', function () {
                if ($(window).scrollTop() > $scPosition) {
                    $('.goTop').addClass('is-show');
                } else {
                    $('.goTop').removeClass('is-show');
                }
            })
        },
        shareMedia: function () {
            $('.share-media').find('li').on('click', function () {
                var url = $(this).find('span').data("link");
                window.open(url, 'sharer', 'toolbar=0,status=0,width=626,height=436');
            });
        },
        openWechat: function () {
            $('.social-media').find('.wechat').on('click', 'a', function () {
                $('.wechat_popup').addClass('is-play');
                return false;
            })

            $('.wechat_popup').find('.overlay').bind('click', function () {
                $('.wechat_popup').removeClass('is-play');
                return false;
            })

            $('.social-media').find('.lineat').on('click', 'a', function () {
                $('.line_popup').addClass('is-play');
                return false;
            })

            $('.line_popup').find('.overlay').bind('click', function () {
                $('.line_popup').removeClass('is-play');
                return false;
            })
        },
        indexSlide: function () {
            if ($('.bxslider-banner').length > 0) {
                var sliderbanner = $('.bxslider-banner').bxSlider({
                    pager: false,
                    infiniteLoop: false
                });
            }
        },
        /*  instagram: function () {
         if ($('.instagram-list').length > 0) {
         $(".instagram-list").jqinstapics({
         "user_id": "17760049",
         "access_token": "17760049.1677ed0.d8ec0daf899c4a0c9ffa1e33a8395696",
         // "user_id": "5687475", // webber.wu for test
         // "access_token": "5687475.1677ed0.a30408d4531145b5885b994d8d78d86d", // webber.wu for test
         "count": 10
         });
         }
         },*/
        sitesearch: function () {
            $('.search-toggle').on('click', function () {
                $('.search').addClass('is-open');
            })
            $('.search').find('.btn-close').on('click', function () {
                $('.search').removeClass('is-open');
            })
        },
        aboutTab: function () {
            $('.lang-toggle').on('click', 'a', function (e) {
                var lang = $(this).attr('data-type');
                $('.section > div').fadeOut('slow');
                $('.section').find('.about-block-' + lang).removeClass('hidden').fadeIn('slow');
                $('.lang-toggle').find('li').removeClass('is-active');
                $(this).parent('li').addClass('is-active');
                e.preventDefault();
            })
        },
        brandInfo: function () {
            $('.brand-list').find('li').on('click', 'a', function (e) {
                var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
                var that = $(this);
                var pages = that.attr('data-page');
                $('.brand-list').find('li').removeClass('is-active');
                that.parent('li').addClass('is-active');
                $.ajax({
                    url: 'brands/' + pages + '.html',
                    dataType: 'html',
                    type: 'GET',
                    error: function () {
                        $('.brand-intro').html('OOOOPS!');
                    },
                    beforeSend: function () {

                    },
                    success: function (response) {
                        // $body.animate({scrollTop: $('.brand-intro').offset().top-100}, 700, 'ease');
                        $body.animate({scrollTop: $('.brand-intro').offset().top - 100}, 700);
                        $('.brand-intro').empty().html(response);

                    },
                    complete: function () {

                    }
                })

                e.preventDefault();
            })
        },
        adjustIframes: function () {
            $('iframe').each(function () {
                var
                    $this = $(this),
                    proportion = $this.data('proportion'),
                    w = $this.attr('width'),
                    actual_w = $this.width();

                if (!proportion) {
                    proportion = $this.attr('height') / w;
                    $this.data('proportion', proportion);
                }

                if (actual_w != w) {
                    $this.css('height', Math.round(actual_w * proportion) + 'px');
                }
            });
        },
        swiperBanner: function () {
            //Testimonial Slider
            var swiper = new Swiper('.testimonial-slider', {
                slidesPerView: 1,
                autoplay: 3000,
                loop: true,
                pagination: '.swiper-pagination',
                paginationClickable: true
            });

        }
    }
})(jQuery);

$(function () {
    iplus.init();
})
function isIE() { //ie?
    if (!!window.ActiveXObject || "ActiveXObject" in window)
        return true;
    else
        return false;
}
function animateRoute(ele, offset, end, speed) {
    if (!isIE())return;
    var _offset = offset;
    var offsetMe = function () {
        if (speed < 0) {
            if (offset < end) offset = _offset;
        } else {
            if (offset > end) offset = _offset;
        }
        ele.style.strokeDashoffset = offset;
        offset = offset + speed;
        requestAnimationFrame(offsetMe);
    }
    offsetMe();
}